import crypt
import os
from tornado import gen
from tornado import web

import sys
sys.path.append("..")

from utils.dbutil import MySQLConnection

class BaseHandler(web.RequestHandler):
    def get_current_user(self):
        user_info = self.get_secure_cookie("user_info")
        if user_info:
            arr = user_info.decode().split('-')
            user = {'accountid':arr[0], 'accountname':arr[1], 'truename':arr[2]}
            return user
            
        return None

# 首页
class MainHandler(BaseHandler):
    @web.authenticated
    @gen.coroutine
    def get(self):
        user = self.get_current_user()
        self.render('index.html', user=user)

class FeatureNotReadyHandler(BaseHandler):
    @web.authenticated
    @gen.coroutine
    def get(self):
        menu_tag = self.get_argument("menutag")
        self.render('featurenotready.html', user=self.get_current_user(), menu_tag=menu_tag)


default_handlers = [
    (r'/', MainHandler),
    (r'/featurenotready', FeatureNotReadyHandler)
]